from typing import Any

from PyQt6.QtCore import QObject, pyqtSignal, QRunnable


class WorkerSignal(QObject):
    finished = pyqtSignal(str)



class Worker(QRunnable):

    def __init__(self, inner, callback):
        super(Worker, self).__init__()
        self.signal = WorkerSignal()
        self.result=''
        self.inner = inner
        self.signal.finished.connect(lambda :callback(self.result))

    def run(self):
        self.result = self.inner()
        # 模拟长时间运行的任务
        # ...
        # 完成后发出信号
        self.signal.finished.emit('任务完成')
